home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 015 / hpljet.arc / LJ2.C < prev    next >
Encoding:
C/C++ Source or Header  |  1986-02-11  |  4.1 KB  |  154 lines

  1. /*
  2.  
  3.     LJ -- A printing utility for the HP LaserJet
  4.  
  5.     This program prints a series of files on the LaserJet printer.  The
  6.     files are printed in a "landscape" font at 17 characters to the inch.
  7.     To take advantage of this density, two "pages" of information from
  8.     the file are printed on each piece of paper (left and right halves).
  9.  
  10.     Usage is:    LJ file1 file2 file3 ...
  11.  
  12.     Where file# is a valid MS-DOS filename, included on the command line.
  13.  
  14.     April 28, 1985     Joe Barnhart
  15.           May 22, 1985     revised by RGD for page #s, date, time 
  16.  
  17.     compiles with Lattice C version 2.15
  18.  
  19. */
  20.  
  21. #include <h\stdio.h>
  22.  
  23. #define  MAXLINE 56
  24. #define     PAGE     '\014'
  25.  
  26. struct                        /* 8086 registers */
  27.     {   int    ax,bx,cx,dx,si,di;
  28.         }   regs;
  29.  
  30. main(argc, argv)
  31.     int   argc;
  32.     char  *argv[];
  33.  
  34. {   int     filenum;
  35.     FILE    *fp,*prn;
  36.  
  37.     prn = fopen("PRN:","w");
  38.     if (prn == NULL)
  39.     printf("%s","Error opening printer as file.\n");
  40.     else
  41.     /* initialize the LaserJet for landscape printing */
  42.     fprintf(prn,"%s","\033E\033&l1O\033(s17H\033&l8d6e57F");
  43.     for (filenum = 1;filenum < argc;filenum++)
  44.         {  fp = fopen(argv[filenum],"r");
  45.        if (fp == NULL)
  46.           printf("%s %s %s\n","File:",argv[filenum],"doesn't exist");
  47.        else
  48.           {  printf("%s %s\n","Now printing",argv[filenum]);
  49.              printfile(fp,prn,argv[filenum]);
  50.              fclose(fp);
  51.           }
  52.          }
  53.          fprintf(prn,"%s","\015\033E");        /* clear LaserJet */
  54. }
  55.  
  56. printfile(fp,prn,filename)
  57.     FILE   *fp,*prn;
  58.     char   *filename;
  59. {
  60.     int pagenum = 0;
  61.  
  62.     while(!feof(fp))
  63.     {   fprintf(prn,"%s","\033&a85m5L\015");    /* select left half */
  64.     pagenum++;
  65.     printpage(fp,prn,filename,pagenum);    /* print one page */
  66.     if (!feof(fp))                /* if more to print... */
  67.     {   fprintf(prn,"%s","\033&a0R");    /* move to top of page */
  68.         fprintf(prn,"%s","\033&a171m91L");    /* select right half */
  69.         pagenum++;
  70.         printpage(fp,prn,filename,pagenum); /* and print another page */
  71.     }
  72.     fputc(PAGE,prn);            /* kick out paper */
  73.     }
  74. }
  75.  
  76. printpage(fp,prn,filename,pagenum)
  77.     FILE   *fp,*prn;
  78.     char   *filename;
  79.     int       pagenum;
  80.  
  81. {   char    c,date[20],time[20];
  82.     int        line,col,i,tablen;
  83.  
  84.     line = 2;  
  85.     col = 0;
  86.     sdatef(date);                /* format date string */
  87.     stimef(time);                  /* format time string */
  88.     fprintf(prn,"File: %-40s",filename);    /* print page header */
  89.     fprintf(prn,"Page %d   %s  %s",pagenum,date,time);
  90.     fputc('\n',prn);                /* two blank lines */ 
  91.     fputc('\n',prn);
  92.     while(line < MAXLINE && (c = fgetc(fp)) != PAGE)
  93.     switch(c)
  94.     {   case '\n':                /* newline found */
  95.         col = 0;            /* zero column and */
  96.         line++;                /* advance line count */
  97.         fputc('\n',prn);
  98.         break;
  99.         case '\t':                /* TAB found */
  100.         tablen = 8 - col % 8;        /* calculate spaces */
  101.         for(i = 1; i <= tablen; i++)    /* and print them */
  102.             fputc('\040',prn);
  103.         col += tablen;
  104.         break;
  105.         case '\xFF':            /* EOF found */
  106.         line = MAXLINE;            /* force termination of loop */
  107.         break;
  108.         default:                /* no special case */
  109.         fputc(c,prn);            /* print character */
  110.         col++;
  111.         break;
  112.     }
  113. }
  114.  
  115.  
  116. getdate(year,month,day)
  117.     int *year,*month,*day;
  118.  
  119. {   regs.ax = 0x2a00;                /* read system date */
  120.     int86(0x21,®s,®s);        
  121.     *month = ( regs.dx >> 8 ) & 255;
  122.     *day   = regs.dx & 255;     
  123.     *year  = regs.cx;
  124. }
  125.  
  126.  
  127. gettime(hours,minutes,seconds)
  128.     int *hours,*minutes,*seconds;
  129.  
  130. {   regs.ax = 0x2c00;                /* read system time */
  131.     int86(0x21,®s,®s);        
  132.     *hours   = ( regs.cx >> 8 ) & 255;
  133.     *minutes = regs.cx & 255;
  134.     *seconds = ( regs.dx >> 8 ) & 255;
  135. }
  136.  
  137.  
  138. sdatef(datestring)                /* format current  */
  139.     char  *datestring;                /* date into ASCII */ 
  140.  
  141. {   int year,month,day;
  142.     getdate(&year,&month,&day);
  143.     sprintf(datestring,"%02d/%02d/%02d",month,day,year-1900);
  144. }
  145.  
  146.  
  147. stimef(timestring)                /* format current  */
  148.     char  *timestring;                /* time into ASCII */
  149.  
  150. {   int hours,minutes,seconds;
  151.     gettime(&hours,&minutes,&seconds);
  152.     sprintf(timestring,"%02d:%02d",hours,minutes);
  153. }
  154.